
import AutoImport from 'unplugin-auto-import/vite'
import legacy from '@vitejs/plugin-legacy'
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { fileURLToPath } from 'url'
import path from 'path'
import pxtorem from 'postcss-pxtorem'


// 获取当前文件的路径
const _filenameNew = fileURLToPath(import.meta.url)

// 返回当前文件的上一次
const _dirnameNew = path.dirname(_filenameNew)


export default defineConfig({
  plugins: [vue(),
  legacy({
    targets: ['defaults', 'ie >= 9', 'chrome 52'],  //需要兼容的目标列表，可以设置多个
    additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
    renderLegacyChunks: true,
    polyfills: [
      'es.symbol',
      'es.array.filter',
      'es.promise',
      'es.promise.finally',
      'es/map',
      'es/set',
      'es.array.for-each',
      'es.object.define-properties',
      'es.object.define-property',
      'es.object.get-own-property-descriptor',
      'es.object.get-own-property-descriptors',
      'es.object.keys',
      'es.object.to-string',
      'web.dom-collections.for-each',
      'esnext.global-this',
      'esnext.string.match-all'
    ]
  }),
  AutoImport({

    include: [
      /\.[tj]sx?$/,
      /\.vue$/,
      /\.vue\?vue/,
      /\.md$/,
      /\.js$/,
    ],

    imports: [
      'vue',
      'pinia',
      'vue-router',
      {
        'element-plus': [
          'ElMessageBox',
          'ElMessage',
          'ElNotification'
        ]
      }
    ],
    eslintrc: {
      enabled: true,
    }

  })
  ],
  resolve: {
    alias: {
      "@": path.resolve(_dirnameNew, './src')
    }
  },
  base: './',
  css: {
    postcss: {
      plugins: [
        pxtorem({
          rootValue: 14,
          propList: ['*']
        })
      ]
    }
  },
  build: {
    sourcemap: false
  },
  server: {
    host: '127.0.0.1',
    port: 5177
  }
})